home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / SOUND / CRYS270.ZIP / ADLIB.ASM next >
Encoding:
Assembly Source File  |  1995-06-26  |  7.8 KB  |  497 lines

  1. ;***************************************************************************
  2. ;*    Driver pour Adlib
  3. ;*
  4. ;* Programmé par Sébastien Granjoux
  5. ;* Commencé le 14/01/95
  6. ;* Modification le 14/01/95
  7.  
  8. IDEAL
  9. P386N
  10.  
  11. INCLUDE "CRYSERR.INC"
  12. INCLUDE "CRYSDEV.INC"
  13.  
  14. PUBLIC    USEADL
  15.  
  16. SEGMENT CODE PARA PUBLIC USE16 'CODE'
  17.  
  18. ASSUME cs:CODE,ds:CODE
  19.  
  20. ;*************************************************************************
  21. ;*    Fonction de detection du driver
  22.  
  23. PROC    USEADL
  24.  
  25.     call    USEDEVICE
  26.     DEVICE <06h,'$',OFFSET setadl,OFFSET startadl,OFFSET stopadl,OFFSET makeadl,OFFSET defbpm,OFFSET peekdef,0,0,0>
  27.  
  28. ENDP
  29.  
  30. ADLPORT    EQU    388h
  31.  
  32. OldInt        DD    0
  33. Counter         DD      0
  34. Count           DD      0
  35. OtherCount      DW      0
  36.  
  37. ;**************************************************************************
  38. ;*    Fixe la valeur d'un registre de la carte adlib
  39. ;*
  40. ;* Entrée:
  41. ;*    AL    numero du registre à modifier
  42. ;*    AH    nouvelle valeur
  43. ;*    DX    adresse de port de la carte adlib
  44.  
  45. PROC    putreg
  46.  
  47.     out    dx,al
  48.     mov    cx,7         ; attend 3.3µs
  49. @@wait_reg:
  50.     in    al,dx
  51.     loop    @@wait_reg
  52.  
  53.     inc    dx
  54.     mov    al,ah
  55.     out    dx,al
  56.     dec    dx
  57.     mov    cx,46
  58. @@wait_data:
  59.     in    al,dx
  60.     loop    @@wait_data
  61.  
  62.     ret
  63.  
  64. ENDP
  65.  
  66. ;***************************************************************************
  67. ;*    routine permettant d'initialiser la carte adlib
  68.  
  69. PROC    setadl
  70.  
  71.     mov    dx,ADLPORT
  72.     mov    ax,6004h
  73.     call    putreg
  74.     mov    ax,8004h
  75.     call    putreg
  76.  
  77.     in    al,dx
  78.     test    al,0E0h
  79.     jz    @@adlib
  80.  
  81.     mov    ax,ADL_NOT_FOUND
  82.     stc
  83.     ret
  84.  
  85. @@adlib:
  86.     mov    [(DEVICE PTR ds:si).irq],0
  87.  
  88.     xor    ax,ax
  89.     call    putreg
  90.  
  91.     mov    ax,02120h
  92.     call    putreg
  93.     mov    ax,03F40h
  94.     call    putreg
  95.     mov    ax,0F060h
  96.     call    putreg
  97.     mov    ax,0F080h
  98.     call    putreg
  99.     mov    ax,000E0h
  100.     call    putreg
  101.  
  102.     mov    ax,03F43h
  103.     call    putreg
  104.  
  105.     mov    ax,001C0h
  106.     call    putreg
  107.  
  108.     mov    cl,[NbVoice]
  109.     call    calvoltab
  110.  
  111.     clc
  112.     ret
  113. ENDP
  114.  
  115. ;***************************************************************************
  116. ;*    routine permettant de démarrer l'envoit du son sur la carte adlib
  117.  
  118. PROC    startadl
  119.  
  120.     cli
  121.     mov    ax,OFFSET soundadl
  122.     mov    dx,cs
  123.     xor    bl,bl
  124.     call    setirq
  125.  
  126.     mov    dx,ADLPORT
  127. @@next_try:
  128.     mov    ax,00B0h
  129.     call    putreg
  130.     mov    ax,8FA0h
  131.     call    putreg
  132.     mov    ax,2EB0h
  133.     call    putreg
  134.     xor    al,al
  135.     out    43h,al
  136.     jmp    $+2
  137.     jmp    $+2
  138.     in    al,40h
  139.     jmp    $+2
  140.     jmp    $+2
  141.     mov    cl,al
  142.     in    al,40h
  143.     jmp    $+2
  144.     jmp    $+2
  145.     mov    ch,al
  146.     cmp    cx,1400h
  147.     jb    @@next_try
  148. AdlTest:
  149.     sub    cx,752h
  150.  
  151. @@wait_wave:
  152.     xor    al,al
  153.     out    43h,al
  154.     jmp    $+2
  155.     jmp    $+2
  156.     in    al,40h
  157.     jmp    $+2
  158.     jmp    $+2
  159.     mov     dl,al
  160.     in    al,40h
  161.     jmp    $+2
  162.     jmp    $+2
  163.     mov    dh,al
  164.     cmp    dx,cx
  165.     ja    @@wait_wave
  166.  
  167.     mov    dx,ADLPORT
  168.     mov    ax,20B0h
  169.     call    putreg
  170.     mov    ax,00A0h
  171.     call    putreg
  172.     mov    ax,3F40h
  173.     call    putreg
  174.  
  175.     mov    al,00110110b
  176.     out     43h,al
  177.     jmp    $+2
  178.     jmp    $+2
  179.  
  180.     mov    dx,1
  181.     mov    ax,0D216h
  182.     div    [ds:MixRate]
  183.  
  184.     out     40h,al
  185.     jmp    $+2
  186.     jmp    $+2
  187.     rol     ax,8
  188.     out     40h,al
  189.     jmp    $+2
  190.     jmp    $+2
  191.     rol    ax,8
  192.  
  193.     movzx    ecx,ax
  194.     mov    eax,80000000h
  195.     xor    edx,edx
  196.     div    ecx
  197.  
  198.     add    eax,eax
  199.     mov     [ds:Counter],eax
  200.     shr     eax,16
  201.     mov     [ds:OtherCount],ax
  202.     mov     ax,[ds:VoicesLen]
  203.     sub     [ds:OtherCount],ax
  204.     mov     [ds:Count],1
  205.  
  206.     sti
  207.  
  208.     ret
  209.  
  210. ENDP
  211.  
  212. ;**************************************************************************
  213. ;*    cette procédure est en fait un bloc que l'on doit mettre à
  214. ;*    l'adresse Voices
  215.  
  216. PROC    makeadl FAR
  217.  
  218.     mov    cl,[NbVoice]
  219.     sub    cl,2
  220.     push    cx
  221.  
  222.     mov    di,OFFSET Voice1
  223.     mov     dx,[(VOICE PTR di).effet]
  224.     call    dx
  225.  
  226.     mov    di,[ds:OFFSET SoundPage]
  227.  
  228.     mov    bx,[(VOICE PTR Voice1).play]
  229.     shl    bx,1
  230.     xor    edx,edx
  231.     mov    dx,[word ptr ds:bx+OFFSET Notes]
  232.  
  233.     ror    edx,10
  234.     mov    cx,[(VOICE PTR Voice1).samplen]
  235.     les    esi,[(VOICE PTR Voice1).adrvoc]
  236.     mov    bx,[(VOICE PTR Voice1).replen]
  237.     cmp    si,cx
  238.     jbe    @@ok1
  239. @@adjust1:
  240.     sub    si,bx
  241.     cmp    si,cx
  242.     ja    @@adjust1
  243. @@ok1:
  244.  
  245.     mov    bx,OFFSET VolumeTab
  246.     mov    al,[MasterVol]
  247.     and    al,[(VOICE PTR Voice1).mute]
  248.     mul    [(VOICE PTR Voice1).volume]
  249.     add    bh,ah
  250.  
  251.     push    ebp
  252. @@voix1:
  253.     add     esi,edx
  254.     mov    al,[byte ptr es:si]
  255.     adc    esi,edx
  256.     xlat
  257.     mov    ah,al
  258.     mov    al,[byte ptr es:si]
  259.     adc    si,0
  260.     xlat
  261.     mov    [ds:di+OFFSET SoundBuf],ax
  262.     add    di,2
  263.  
  264.     cmp    di,bp
  265.     jne    @@voix1
  266.     rol    ebp,16
  267.     xor    di,di
  268.     cmp    bp,BUF_LEN
  269.     jne    @@voix1
  270.     pop    ebp
  271.  
  272.     mov    [dword ptr ((VOICE PTR Voice1).adrvoc)],esi
  273.  
  274.     pop    cx
  275.     mov    di,OFFSET Voice1+SIZE VOICE
  276. @@next_voice:
  277.     push    cx
  278.     mov     dx,[(VOICE ptr ds:di).effet]
  279.     call    dx
  280.  
  281.     mov    bx,[(VOICE ptr ds:di).play]
  282.     shl    bx,1
  283.     xor    edx,edx
  284.     mov    dx,[word ptr ds:bx+OFFSET Notes]
  285.     ror    edx,10
  286.     mov    cx,[(VOICE ptr ds:di).samplen]
  287.     les    esi,[(VOICE ptr ds:di).adrvoc]
  288.     mov    bx,[(VOICE ptr ds:di).replen]
  289.     cmp    si,cx
  290.     jbe    @@ok2
  291. @@adjust2:
  292.     sub    si,bx
  293.     cmp    si,cx
  294.     ja    @@adjust2
  295. @@ok2:
  296.  
  297.     mov    bx,OFFSET VolumeTab
  298.     mov    al,[MasterVol]
  299.     and    al,[(VOICE PTR ds:di).mute]
  300.     mul    [(VOICE PTR ds:di).volume]
  301.     add    bh,ah
  302.  
  303.     push    di
  304.  
  305.     push    ebp
  306.     mov    di,[ds:OFFSET SoundPage]
  307. @@voix2:
  308.     add     esi,edx
  309.     mov    al,[byte ptr es:si]
  310.     adc    esi,edx
  311.     xlat
  312.     mov    ah,al
  313.     mov    al,[byte ptr es:si]
  314.     adc    si,0
  315.     xlat
  316.     add    [ds:di+OFFSET SoundBuf],ax
  317.     add    di,2
  318.  
  319.     cmp    di,bp
  320.     jne    @@voix2
  321.     rol    ebp,16
  322.     xor    di,di
  323.     cmp    bp,BUF_LEN
  324.     jne    @@voix2
  325.     pop    ebp
  326.  
  327.  
  328.     pop    di
  329.     mov    [dword ptr ((VOICE ptr ds:di).adrvoc)],esi
  330.     add    di,SIZE VOICE
  331.     pop    cx
  332.     dec    cl
  333.     jne    @@next_voice
  334.  
  335.     mov     dx,[(VOICE ptr ds:di).effet]
  336.     call    dx
  337.  
  338.     mov    bx,[(VOICE ptr ds:di).play]
  339.     shl    bx,1
  340.     xor    edx,edx
  341.     mov    dx,[word ptr ds:bx+OFFSET Notes]
  342.     ror    edx,10
  343.     mov    cx,[(VOICE ptr ds:di).samplen]
  344.     les    esi,[(VOICE ptr ds:di).adrvoc]
  345.     mov    bx,[(VOICE ptr ds:di).replen]
  346.     cmp    si,cx
  347.     jbe    @@ok4
  348. @@adjust4:
  349.     sub    si,bx
  350.     cmp    si,cx
  351.     ja    @@adjust4
  352. @@ok4:
  353.  
  354.     mov    bx,OFFSET VolumeTab
  355.     mov    al,[MasterVol]
  356.     and    al,[(VOICE ptr ds:di).mute]
  357.     mul    [(VOICE ptr ds:di).volume]
  358.     add    bh,ah
  359.  
  360.     push    di
  361.     mov    di,[ds:OFFSET SoundPage]
  362. @@voix4:
  363.     add     esi,edx
  364.     mov    al,[byte ptr es:si]
  365.     adc    esi,edx
  366.     xlat
  367.     mov    ah,al
  368.     mov    al,[byte ptr es:si]
  369.     adc    si,0
  370.     xlat
  371.     add    [ds:di+OFFSET SoundBuf],ax
  372.     add    di,2
  373.  
  374.     cmp    di,bp
  375.     jne    @@voix4
  376.     rol    ebp,16
  377.     xor    di,di
  378.     cmp    bp,BUF_LEN
  379.     jne    @@voix4
  380.  
  381.     pop    di
  382.     mov    [dword ptr ((VOICE ptr ds:di).adrvoc)],esi
  383.  
  384. @@fin4voice:
  385.  
  386.     shr    ebp,16
  387.     and    bp,65535-BUF_LEN
  388.     mov    [word ptr ds:OFFSET SoundPage],bp
  389.     mov    [byte ptr cs:OFFSET switch_makemod],1Eh
  390.  
  391.     pop    edi
  392.     pop    esi
  393.     pop    ebp
  394.     pop    es
  395.     pop    ds
  396.  
  397.     ret
  398.  
  399. ENDP
  400.  
  401. ;***************************************************************************
  402. ;*      interruption 8 permettant d'envoyer le son sur le speaker
  403.  
  404. PROC    soundadl FAR
  405.  
  406.     push    eax
  407.     push    bx
  408.     push    dx
  409.  
  410.     mov    bx,[cs:OFFSET SoundPtr]
  411.     inc    bx
  412.     and    bx,65535-BUF_LEN
  413.     mov    [cs:OFFSET SoundPtr],bx
  414.     mov    al,[cs:bx+OFFSET SoundBuf]
  415.  
  416.     mov    bx,OFFSET AMPLI8
  417.     xlat    [cs:bx]
  418.  
  419.     mov    dx,ADLPORT+1
  420.     out    dx,al
  421.  
  422.     pop    dx
  423.     pop    bx
  424.  
  425.     dec    [word cs:OFFSET Count+2]
  426. irq_switch:
  427.     jle    @@imakemod
  428.  
  429.     mov    al,20h
  430.     out    20h,al
  431.  
  432.     pop    eax
  433.     iret
  434.  
  435. @@int08:
  436.     mov     ax,[word ptr cs:OFFSET Counter+2]
  437.     xchg    ax,[cs:OtherCount]
  438.     add     [cs:OFFSET Count+2],ax
  439.     sub     [cs:OtherCount],ax
  440.     add     [byte ptr cs:OFFSET irq_switch+1],OFFSET @@imakemod - OFFSET @@int08
  441.     pop    eax
  442.     jmp    [dword ptr cs:OldIrq]
  443.  
  444. @@imakemod:
  445.  
  446.     mov    al,20h
  447.     out    20h,al
  448.  
  449.     mov     ax,[cs:VoicesLen]
  450.     cmp     ax,[cs:OtherCount]
  451.     jb      @@next_make
  452.     xchg    ax,[cs:OtherCount]
  453.     sub     [cs:OtherCount],ax
  454.     shl     eax,16
  455.     mov     ax,[word ptr cs:Counter]
  456.     add     [cs:OFFSET Count],eax
  457.     sub     [byte ptr cs:OFFSET irq_switch+1],OFFSET @@imakemod - OFFSET @@int08
  458.     pop     eax
  459.  
  460.     jmp     IMAKEMOD
  461.  
  462. @@next_make:
  463.         sub     [cs:OtherCount],ax
  464.         add     [word ptr cs:OFFSET Count+2],ax
  465.     pop     eax
  466.  
  467.     jmp     IMAKEMOD
  468.  
  469. ENDP
  470.  
  471. ;***************************************************************************
  472. ;*    cette routine permet d'arreter l'envoit du son sur le speaker
  473.  
  474. PROC    stopadl
  475.  
  476.     cli
  477.     mov    dx,ADLPORT
  478.     mov    ax,000B0h
  479.     call    putreg
  480.  
  481.     mov     al,00110110b
  482.     out     43h,al
  483.     jmp    $+2
  484.     jmp    $+2
  485.     xor    al,al
  486.     out     40h,al
  487.     jmp    $+2
  488.     jmp    $+2
  489.     out     40h,al
  490.  
  491.     ret
  492.  
  493. ENDP
  494.  
  495. ENDS
  496.  
  497. END